import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/context/my_build_contest.dart';
import 'package:flutter_demo/ui/pages/getx/count/count_controller.dart';
import 'package:get/get.dart';

// ignore: slash_for_doc_comments
/**
 * 处理页面展示
 */
class Snackbar extends StatelessWidget {
  static const String routeName = "/getx/snackbar";
  const Snackbar({super.key});

  @override
  Widget build(BuildContext context) {
    final countController = Get.find<CountController>();

    return Scaffold(
        appBar: AppBar(
          title: Obx(() => Text("Getx snackbar${countController.get()}")),
          centerTitle: true,
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              child: const Text("snackbar"),
              onPressed: () {
                Get.snackbar("标题", "网络错误", //默认标题
                    colorText: Colors.white,
                    backgroundColor: Colors.black54,
                    duration: const Duration(seconds: 5),
                    snackPosition: SnackPosition.BOTTOM,
                    //自定义标题
                    titleText: Text(
                      "新标题${context.hello}",
                      style: TextStyle(color: Colors.blue),
                    ),
                    messageText: Column(
                      children: const [
                        Icon(
                          Icons.add,
                          color: Colors.white,
                        ),
                        Icon(
                          Icons.delete,
                          color: Colors.white,
                        ),
                        Icon(
                          Icons.mode_edit,
                          color: Colors.white,
                        )
                      ],
                    ),
                    icon: const Icon(Icons.usb_off));
              },
            ),
            ElevatedButton(
              child: const Text("dialog"),
              onPressed: () {
                Get.defaultDialog(
                    title: "标题",
                    titleStyle: const TextStyle(color: Colors.red),
                    content: Column(
                      children: const [Text("数据1"), Text("数据2"), Text("数据3")],
                    ),
                    textCancel: "取消",
                    textConfirm: "确认",
                    confirmTextColor: Colors.white,
                    onConfirm: () {
                      Get.back();
                      Get.snackbar("购物", "确认成功");
                    });
              },
            ),
            ElevatedButton(
              child: const Text("bottomsheet"),
              onPressed: () {
                Get.bottomSheet(
                  Container(
                    height: 300,
                    color: Colors.white,
                    child: ListView(
                      children: const [
                        ListTile(
                          title: Text("重启"),
                          leading: Icon(Icons.abc),
                          trailing: Icon(Icons.abc),
                        ),
                        ListTile(title: Text("休眠")),
                        ListTile(title: Text("关机")),
                      ],
                    ),
                  ),
                );
              },
            ),
          ],
        ));
  }
}
